package com.ouken.tool;


import com.ouken.com.R;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class RanklistAdapter extends BaseAdapter {
	Context context;  
    String[] contents; //formate is (OK,OK,name,point,name,point)
    
	public RanklistAdapter(Context context,String[] contents) {
		this.context=context;  
        this.contents=contents;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return (contents.length - 4)/2;  
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position+" "+contents[2*position + 2]+" "+contents[2*position + 1 + 2];  
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;  
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if(convertView==null){  
            LayoutInflater inflater=LayoutInflater.from(context);  
            convertView=inflater.inflate(R.layout.ranklist_item, null);  
        }  
        TextView t_rank=(TextView)convertView.findViewById(R.id.adapter_ranklist_tv_rank);  
        TextView t_name=(TextView)convertView.findViewById(R.id.adapter_ranklist_tv_name);  
        TextView t_point=(TextView)convertView.findViewById(R.id.adapter_ranklist_tv_point);  
        
        if(position < 5){
        	t_rank.setText(Integer.toString(position+1));  
            t_rank.setTextColor(Color.MAGENTA);  
            t_rank.setTextSize(25);  
            t_rank.setGravity(Gravity.LEFT);
        
        
        t_name.setText(contents[2*position + 2]); 
        t_name.setGravity(Gravity.CENTER);
  
        if(contents[2*position + 2].equals("waiting"))
        {
        	t_name.setTextColor(Color.RED); 
        }else{
        	t_name.setTextColor(Color.BLUE); 
        }
         
        t_name.setTextSize(25);  
        
        t_point.setText(contents[2*position + 1 + 2]);  
        t_point.setTextColor(Color.DKGRAY);  
        t_point.setTextSize(25); 
        t_point.setGravity(Gravity.RIGHT);
        }
        return convertView;  
	}

}
